<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\model\Message;

class MessageController extends Controller
{
  
    public function index(Request $request)
    {
    	$label = '留言管理';
    	if ($request->ajax()) {
    		//后台用户列表接口
            $page = $request->page ? $request->page : 1;
            $limit = $request->limit ? $request->limit : 10;
            $offset = ($page - 1) * $limit;
            $count = Message::count('id');
    
            $messageMsg = Message::limit($limit)->offset($offset)->get();

            if (!empty($messageMsg)) 
            {
                foreach ($messageMsg as $key => &$value) 
                {
                    $value['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
                    unset($value);
                }
            }
            return $this->return_ajax_data($messageMsg,'','',$count);
    	}
    	return view('admin.message.index',compact('label'));
    }

    public function msgDel(Request $request)
    {
    	$id = $request->id;
        $status = Message::where('id','=',$id)->delete();
        return $this->call_back_status($status);
    }
}
